import { ApiCall } from "tsrpc";
import { ReqCreateRoom, ResCreateRoom } from "../../../tsrpc/shared/protocols/room/PtlCreateRoom";
import { ecs } from "../../../core/ecs/ECS";
import { Room } from "../../../module/room/Room";
import { rs } from "../../../RoomServiceEntra";

export default async function (call: ApiCall<ReqCreateRoom, ResCreateRoom>) {
    if (call.req.roomName.length == 0) {
        call.error("房间名字不能为空",{code:"ROOM_NAME_INVAILD"});
        return;
    }
    // TODO
    const room = ecs.getEntity<Room>(Room);
    room.RoomModel.roomName = call.req.roomName;
    room.RoomModel.password = call.req.password;
    const roomId = room.RoomModel.roomId;
    rs.RoomServiceModel.rooms.set(roomId, room);
    
    call.succ({
        roomId: roomId
    })
    
}